# -*-coding:utf-8-*-
'''
File Create by Author:Backpackerxl
Create File Time:2021/10/14/014 11:15
Program IDE:PyCharm
File Name:UserLogin.py
  
'''
from entity.BankUser import BankUser
from util.WatchInput import WatchInput as u_input


class UserLogin:
    def three_login(self, user_data):
        for i in range(3):
            u_id = u_input.WatchInput(self, "请输入卡号")
            u_passwd = u_input.WatchInputPwd(self, "请输入密码")
            user = [user for user in user_data if u_id == user["user_bank_id"]]
            if len(user) == 0:
                print("账户或密码错误")
            else:
                user = BankUser(user[0]["user_name"],
                                user[0]["user_sex"],
                                user[0]["user_id"],
                                user[0]["user_phone"],
                                user[0]["user_money"],
                                user[0]["user_password"],
                                user[0]["user_bank_id"],
                                user[0]["user_use_state"], )
                if user.get_user_password() == u_passwd:
                    if user.get_user_use_state() == 0:
                        return True, user
                    else:
                        return False, user
                    break
                else:
                    print("账户或密码错误")
            if i == 2 and user.get_user_password() != u_passwd:
                user_data.remove(user.user_to_dic())
                user.set_user_use_state(1)
                user_data.append(user.user_to_dic())
                print(":) 对不起，您的账户已经冻结。")
                return ()
